//
//  CouponTableViewCell.m
//  customer
//
//  Created by Tank on 2019/4/1.
//  Copyright © 2019 yinlong. All rights reserved.
//

#import "CouponTableViewCell.h"
#import <SDAutoLayout.h>
@interface CouponTableViewCell()

@property (nonatomic,strong)UIView *baseView;

/**
 价格：
 */
@property (nonatomic,strong)UILabel *priceLabel;

/**
 //名字
 */
@property (nonatomic,strong)UILabel *couponTitleLabel;

/**
 描述
 */
@property (nonatomic,strong)UILabel *descriptionLabel;

/**
 时间
 */
@property (nonatomic,strong)UILabel *usableRangeLabel;

/**
 适用范围  use_scene 使用场景 (1维修2设计3装修4改造5加配)
 */
@property (nonatomic,strong)UILabel *timeLabel;

@end

@implementation CouponTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        AutoWeakSelf
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.contentView.backgroundColor = [UIColor clearColor];
        self.backgroundColor = [UIColor clearColor];
        
        _baseView = [[UIView alloc]init];
        _baseView.backgroundColor = [UIColor whiteColor];
        [self.contentView addSubview:_baseView];
        
        [_baseView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.contentView).offset(16);
            make.right.equalTo(weakSelf.contentView).offset(-16);
            make.bottom.equalTo(weakSelf.contentView);
            make.top.equalTo(weakSelf.contentView).offset(10);
        }];
        
        _priceLabel = [[UILabel alloc]init];
        _priceLabel.text = @"";
        _priceLabel.font = Font(16);
        _priceLabel.textColor = [UIColor whiteColor];
        _priceLabel.backgroundColor = [HSPublic colorWithHexString:@"#0582F5"];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
        [_baseView addSubview:_priceLabel];
        [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.bottom.equalTo(weakSelf.baseView);
            make.width.equalTo(weakSelf.baseView).multipliedBy(0.33);
        }];
        
        _couponTitleLabel = [[UILabel alloc]init];
        _couponTitleLabel.font = [UIFont boldSystemFontOfSize:14];
        _couponTitleLabel.textAlignment = NSTextAlignmentLeft;
        _couponTitleLabel.textColor = [HSPublic colorWithHexString:@"#101010"];
        [_baseView addSubview:_couponTitleLabel];
        [_couponTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.priceLabel.mas_right).offset(15);
            make.top.equalTo(weakSelf.baseView).offset(10);
        }];
        
        _descriptionLabel = [[UILabel alloc]init];
        _descriptionLabel.font = Font(12);
        _descriptionLabel.textAlignment = NSTextAlignmentLeft;
        _descriptionLabel.textColor = [HSPublic colorWithHexString:@"#101010"];
        _descriptionLabel.numberOfLines = 2;
        _descriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [_baseView addSubview:_descriptionLabel];
        [_descriptionLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.priceLabel.mas_right).offset(15);
            make.top.equalTo(weakSelf.couponTitleLabel.mas_bottom).offset(10);
        }];
        
        _usableRangeLabel = [[UILabel alloc]init];
        _usableRangeLabel.font = Font(12);
        _usableRangeLabel.textAlignment = NSTextAlignmentLeft;
        _usableRangeLabel.textColor = [HSPublic colorWithHexString:@"#101010"];
        _usableRangeLabel.numberOfLines = 2;
        _usableRangeLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [_baseView addSubview:_usableRangeLabel];
        [_usableRangeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.priceLabel.mas_right).offset(15);
            make.top.equalTo(weakSelf.descriptionLabel.mas_bottom).offset(10);
        }];
        
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = Font(12);
        _timeLabel.textAlignment = NSTextAlignmentLeft;
        _timeLabel.textColor = [HSPublic colorWithHexString:@"#101010"];
        [_baseView addSubview:_timeLabel];
        [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(weakSelf.priceLabel.mas_right).offset(15);
            make.bottom.equalTo(weakSelf.priceLabel.mas_bottom).offset(-10);
        }];
        
    }
    return self;
}


/**
 优惠劵接口 新增字段 ：
 use_scene 使用场景 (1维修2设计3装修4改造5加配)
 rule_value 使用规则(判断计算满减用，满减阀值)
 rule_remark 使用规则（文字解：满100减90)
 rule 1 满减劵，2打折劵
 money 改变为double类型   （rule为1时为满减值，2时为打折率）
 */

-(void)cellForLayoutCouponCell:(CouponListModel *)model{
    self.priceLabel.text = [model.rule isEqualToString:@"1"]?[NSString stringWithFormat:@"￥%@", [NSNumber numberWithDouble:[model.money doubleValue]]]:[NSString stringWithFormat:@"%@折", [NSNumber numberWithDouble:[model.money doubleValue]*10]];
    switch ([model.use_scene integerValue]) {
        case 1:
            self.usableRangeLabel.text = @"使用场景:维修";
            break;
        case 2:
            self.usableRangeLabel.text = @"使用场景:设计";
            break;
        case 3:
            self.usableRangeLabel.text = @"使用场景:装修";
            break;
        case 4:
            self.usableRangeLabel.text = @"使用场景:改造";
            break;
        case 5:
            self.usableRangeLabel.text = @"使用场景:加配";
            break;
        default:
            break;
    }
    self.couponTitleLabel.text = model.title;
    self.descriptionLabel.text = model.rule_remark;
    self.timeLabel.text = model.sx_at;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    // Configure the view for the selected state
}

@end

